Skip to content

Conversation

@ayush1999
Copy link
Contributor

using the normal input() function was causing a NameError.
changing it to raw_input() fixed this.

using the normal input() function was causing a NameError.
changing it to raw_input() fixed this.
@shreydan
Copy link
Contributor

shreydan commented May 31, 2017

@ayush1999 this program is written in Python 3.

@shreydan
Copy link
Contributor

@ayush1999 also I do have a NameError Exception in the program and it works.

print ("\nScientific Calculator\nEg: pi * sin(90) - sqrt(81)")

k = input("\nWhat is ")
k = raw_input("\nWhat is ") # Using input() function is causing NameError. Changing it to raw_input() fixes this.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ayush1999 python3 input will give you a string no matter what you input.py2 is different so,raw_input =>string,and input may result in a number if you input like"1+2".if wrong,thanks for telling me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In python 2, raw_input will always return a string, however input will treat it as an expression.
In Python 3, input returns a string. Maybe this helps!

@geekcomputers geekcomputers merged commit cc99f74 into geekcomputers:master Jun 3, 2017
@geekcomputers
Copy link
Owner

geekcomputers commented Jun 3, 2017 via email

@ayush1999
Copy link
Contributor Author

Can someone please tell me how *args and **kwargs work in Python?
I am having difficulty in using them.
Thanks!

@HidekiHokuto
Copy link
Contributor

HidekiHokuto commented Jun 7, 2017

@ayush1999
*args is used to send a non-keyworded variable argument list to the function.
**kwargs is used to pass keyworded variable of arguments to a function.

def foo(first, *args, **kwargs):
    print('Required argument: ', first)
    for v in args:
        print('Optional argument (*args): ', v)
    for k, v in kwargs.items():
        print('Optional argument %s (*kwargs): %s' % (k, v))

>>> foo(1, 2, 3, 4, k1=5, k2=6)

Required argument: 1
Optional argument (*args): 2
Optional argument (*args): 3
Optional argument (*args): 4
Optional argument k2 (*kwargs): 6
Optional argument k1 (*kwargs): 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants